using mapshiftApplication.Repositories;
using Microsoft.AspNetCore.Connections;
using Oracle.ManagedDataAccess.Client;

namespace mapshiftApplication;

public class OracleConnectionFactory(IConfiguration configuration) : IOracleConnectionFactory
{
    public OracleConnection GetConnection(string name)
    {
        var connStr = configuration.GetConnectionString(name);
        if (string.IsNullOrWhiteSpace(connStr))
        {
            throw new ArgumentException($"No connection string found for key: {name}");
        }

        return new OracleConnection(connStr);
    }
}


public static class DependencyInjection
{
    public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration config)
    {
        services.AddSingleton<IOracleConnectionFactory, OracleConnectionFactory>();
        services.AddScoped<IIssueRepository, IssueRepository>();
        services.AddScoped<IOtdRepository, OtdRepository>();
        return services;
    }
}
